<%@page import="entities.Template"%>
<%@page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory"%>
<%@page import="com.google.appengine.api.blobstore.BlobstoreService"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.UrlHelper"%>

<%
TreeMap check = (TreeMap) request.getAttribute("check");
String success = (String) request.getAttribute("success");
Template template = (Template) request.getAttribute("template");
String form = (String) request.getAttribute("form");

BlobstoreService blobService = BlobstoreServiceFactory.getBlobstoreService();
String action = blobService.createUploadUrl("/admin/template/add");
if (form.equalsIgnoreCase("edit")) {
	action = blobService.createUploadUrl("/admin/template/edit/" + template.getId());
}
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/admin/layouts/header.jsp" />

<script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="/admin/js/application_template_form.js"></script>

		<div class="maincontent noright">
        	<div class="maincontentinner">
                <ul class="maintabmenu multipletabmenu">
                	<li><a href="/admin/template/list">Template Manager</a></li>
                	<li class="current"><a href="#"><%=form.equalsIgnoreCase("edit") ? "Edit Template" : "Add New Template" %></a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">
					<jsp:include page="/admin/elements/message_box.jsp" />
                    
                    <div class="">
	                    <form class="stdform stdform2" action="<%=action%>" method="post" enctype="multipart/form-data">
	                    	<p>
	                        	<label>Title</label>
	                            <span class="field">
	                            	<input type="text" class="mediuminput" name="title" id="a_title" value="<%=template.getTitle() != null ? template.getTitle() : "" %>">
	                            	<% if (check.get("title") != null) { %>
										<label for="g_title" generated="true" class="error"><%=check.get("title") %></label>
									<% } %>
	                            </span>
	                        </p>
	                        
	                        <p>
	                        	<label>Description</label>
	                            <span class="field">
	                            	<textarea class="mediuminput" name="description" id="a_description" ><%=template.getDescription() != null ? template.getDescription() : "" %></textarea>
	                            	<% if (check.get("description") != null) { %>
										<label for="g_description" generated="true" class="error"><%=check.get("description") %></label>
									<% } %>
	                            </span>
	                        </p>
	                        
	                        <p>
	                        	<label>Template Upload</label>
	                            <span class="field">
	                            	<input type="file" title="Template Data" name="data">
	                            	<% if (check.get("dirUpload") != null) { %>
										<label for="a_dirUpload" generated="true" class="error"><%=check.get("dirUpload") %></label>
									<% } %>
	                            </span>
	                        </p>
	                    
		                    <p class="stdformbutton">
		                    	<button class="stdbtn btn_black">Save All Change</button>
		                    </p>
	                    </form>
                    </div>
                    
                    <br clear="all">
                    
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp" />
            
        </div>

<jsp:include page="/admin/layouts/footer.jsp" />